package com.llkj.common.observer;

import com.llkj.common.exception.ApiException;
import com.llkj.common.mvp.IView;

/**
 * author: zhu.px
 * e-mail: 1271901673@qq.com
 * time  : 2018/5/9
 * desc  :
 */
public abstract class BaseDialogObserver<T> extends BaseObserver<T> {

    private IView mIView;
    private boolean isRefresh;

    public BaseDialogObserver(IView mIView) {
        this.mIView = mIView;
    }

    public BaseDialogObserver(IView mIView, boolean isRefresh) {
        this.mIView = mIView;
        this.isRefresh = isRefresh;
    }

    @Override
    public void doOnStart() {
        if (!isRefresh) {
            mIView.showLoadingDialog("");
        }
    }

    @Override
    public void doOnCompleted() {
        if (!isRefresh) {
            mIView.hideLoadingDialog();
        } else {
            mIView.finishRefresh();
        }
    }

    @Override
    public void doOnError(ApiException e) {
        if (!isRefresh) {
            mIView.hideLoadingDialog();
        } else {
            mIView.finishRefresh();
        }
        mIView.showMessage(e.getMessage());
    }
}
